home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Classes / SocketClasses / Chat / chat_main.m < prev    next >
Encoding:
Text File  |  1992-07-23  |  5.7 KB  |  119 lines

  1. /***************************************************************************
  2. *                                                                          *
  3. * Chat_main.m                                                              *
  4. * Copyright 1992 by Nik A Gervae                                           *
  5. *                                                                          *
  6. * Part of an example using the Objective-C classes (SktSocketManager,      *
  7. * SktSocket, and SktSocketUser) which implement a convenient interface to  *
  8. * Berkeley stream sockets under NeXTSTEP(r).  See the accompanying class   *
  9. * specifications (files with a .rtf or .spec suffix) and the sources for   *
  10. * further information.                                                     *
  11. *                                                                          *
  12. * NeXTSTEP is a registered trademark of NeXT Computer, Inc.                *
  13. *                                                                          *
  14. ****************************************************************************
  15. *                                                                          *
  16. * LICENSE                                                                  *
  17. *                                                                          *
  18. * This program is free software; you can redistribute it and/or modify     *
  19. * it under the terms of the GNU General Public License as published by     *
  20. * the Free Software Foundation.                                            *
  21. *                                                                          *
  22. * The program and this makefile are distributed in the hope that it will   *
  23. * be useful, but are provided "AS IS" AND WITHOUT ANY WARRANTY; without    *
  24. * any express or implied warranty of MERCHANTABILITY or FITNESS FOR A      *
  25. * PARTICULAR PURPOSE. See the GNU General Public License for more details. *
  26. * Any use or distribution of the program and documentation must include    *
  27. * appropriate copyrights to acknowledge Nik A. Gervae and the Free         *
  28. * Software Foundation, Inc.                                                *
  29. *                                                                          *
  30. * You should have received a copy of the GNU General Public License        *
  31. * along with this program; if not, write to the Free Software              *
  32. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                *
  33. *                                                                          *
  34. ****************************************************************************
  35. *                                                                          *
  36. * VERSION HISTORY                                                          *
  37. *                                                                          *
  38. * Version numbers are simply dates in the form YYYYMMDD.  These represent  *
  39. * the date that version was finished.  Only significantly changed versions *
  40. * are reported here, or those versions requiring explanation of changes.   *
  41. * There may be many interim stages between dated versions.                 *
  42. *                                                                          *
  43. * DateVersion Primary Author  Notes                                        *
  44. * ----------- --------------- -------------------------------------------- *
  45. * 19920327    Nik A Gervae    First released version                       *
  46. *                                                                          *
  47. ***************************************************************************/
  48.  
  49. #import <stdlib.h>
  50. #import <stdio.h>
  51. #import <ctype.h>
  52.  
  53. #import <sys/types.h>
  54. #import <netinet/in.h>
  55.  
  56. #import <objc/Object.h>
  57.  
  58. #import "Chatserver.h"
  59. #import "chat_main.h"
  60.  
  61. id Global_Chatserver;  // the controller for program
  62.  
  63. /***************************************************************************
  64. *                                                                          *
  65. * These are the constant strings used.  Feel free to translate them into   *
  66. * your favorite language.  Do be sure to keep all the % directives in      *
  67. * place, or change the code that accesses these strings.                   *
  68. *                                                                          *
  69. ***************************************************************************/
  70. #define STR_ReservedPort       "Attempt to use a reserved port (%d).\n"
  71. #define STR_DefaultPortInstead "Trying default Internet port instead (%d).\n"
  72. #define STR_TryingDefaultPort  "Trying default Internet port (%d).\n"
  73.  
  74.  
  75.  
  76. /***************************************************************************
  77. *                                                                          *
  78. * main()                                                                   *
  79. *                                                                          *
  80. * Check the args, make a server, and go!                                   *
  81. *                                                                          *
  82. ***************************************************************************/
  83. int main(int argc, char *argv[]) 
  84. {
  85.   int      inetPort;
  86.  
  87.  /*
  88.   * Check cmd line args.
  89.   */
  90.   if (1 < argc) {
  91.  
  92.     if ((inetPort = atoi(argv[1])) < IPPORT_RESERVED) {
  93.       fprintf(stderr, STR_ReservedPort, inetPort);
  94.       fprintf(stderr, STR_DefaultPortInstead, DFLT_INETPORT);
  95.       inetPort = DFLT_INETPORT;
  96.     }
  97.  
  98.   }
  99.   else {
  100.     inetPort = DFLT_INETPORT;
  101.     fprintf(stderr, STR_TryingDefaultPort, DFLT_INETPORT);
  102.   }
  103.  
  104.  /*
  105.   * Make a new controller/server.
  106.   */
  107.   Global_Chatserver = [[Chatserver alloc] initWithInetPort:inetPort];
  108.  
  109.   if (!Global_Chatserver) exit(1);
  110.  
  111.  /*
  112.   * Run forever. Ctrl-C is a handy way to bomb out of the server.
  113.   */
  114.   [Global_Chatserver run];
  115.   [Global_Chatserver shutdown];
  116.  
  117.   exit(0);
  118.  
  119. } /*main*/